#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdio.h>
#include <ctype.h>
#define N 16

int jz(char str[]) {
	int i, n = 0, slen;
	slen = strlen( str);
	for (i = slen - 1; i >= 0; i--)
		if (toupper(str[i]) >= 'A' && toupper(str[i]) <= 'Z')
			n = n + (toupper(str[i]) - 'A' + 10) * pow(N, (slen - i - 1));
		else if (str[i] >= '0' && str[i] <= '9')
			n = n + (str[i] - '0') * pow(N, (slen - i - 1));
	return n;
}

int main() {
	char x[20];
	int n;
	gets(x);
	n = jz(x);
	printf("%d", n);
}
